import express from 'express';
import 'express-async-errors';
import './socket-io/app.js';
import {config} from "./config/portConfig.js";
import managerRouter from "./routes/manager.js";
import userRouter from "./routes/user.js";
import userfriendgroup from "./routes/userfriendgroup.js";
import groupbaseinfo from "./routes/groupbaseinfo.js";
import {authToken} from './middleware/JWTToken.js';
import {exceptionHandle} from './exception.js';
import cors from 'cors';

let app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({extended: false}));
const HTTP_PORT = config.HTTP_PORT;

app.use(authToken);
app.use('/manager', managerRouter);
app.use('/user', userRouter);
app.use('/userfriendgroup', userfriendgroup);
app.use('/groupbaseinfo', groupbaseinfo);
app.get("/test", (req, res, next) => {
  setTimeout(()=>{
    throw new Error("jkasdhkjas");
  }, 1000);
  // throw new Error("666");
});
// 这个异常处理需要放后面
app.use(exceptionHandle);

app.listen(HTTP_PORT, () => {
  console.log(`Serveice is start on ${HTTP_PORT} PORT!`);
});


// process.on('uncaughtException', (err) => {
//     console.error(err);
//
// });
//
// process.on('unhandledRejection', (err) => {
//     console.log('unhandled exception', err);
// })
